{extend name="main" /}

{block name="title_seo"}
<title>首页</title>
<meta name="keywords" charset="UTF-8" content="">
<meta name="description" content="">
{/block}

{block name="body"}
<div class="layui-container">
    <div class="layui-row layui-col-space30" style="padding: 150px 0;text-align: center; margin-top: 60px;" >
        <style>
            .demo-login-container{width: 320px; margin: 21px auto 0;}
            .demo-login-other .layui-icon{position: relative; display: inline-block; margin: 0 2px; top: 2px; font-size: 26px;}
        </style>
        <form class="layui-form">
            <div class="demo-login-container">
                <div class="layui-form-item">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-username"></i>
                        </div>
                        <input type="text" name="username" value="" lay-verify="required" placeholder="账号" lay-reqtext="请填写登录账号" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-password"></i>
                        </div>
                        <input type="password" name="password" value="" lay-verify="required" placeholder="密码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                    </div>
                </div>
                {if condition="xn_cfg('login.show_captcha') eq 1"}
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <div class="layui-input-wrap">
                                <div class="layui-input-prefix">
                                    <i class="layui-icon layui-icon-vercode"></i>
                                </div>
                                <input type="text" name="captcha" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                            </div>
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img src="{:url('login/captcha')}" class="" style="max-height: 40px" id="captcha">
                            </div>
                        </div>
                    </div>
                </div>
                {/if}
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登录</button>
                </div>
                <div class="layui-form-item demo-login-other" style="text-align: center">
                    <a href="{:url('forget')}">忘记密码？</a> &nbsp;
                    <a href="{:url('register')}">注册帐号</a>
                </div>
            </div>
        </form>
    </div>
</div>

<br><br><br>
{/block}

{block name="js"}
<script>
    layui.use(function(){
        var form = layui.form;
        var layer = layui.layer;
        // 提交事件
        form.on('submit(demo-login)', function(data){
            var field = data.field; // 获取表单字段值
            var url = "{:url('login/login')}";
            $.post(url,field,function (res) {
                if ( res.code === 1 ) {
                    layer.msg(res.msg,{icon:1,time:1500},function () {
                        window.location.href = "{:url('user/index')}";
                    });
                } else {
                    $('#captcha').attr('src', "{:url('login/captcha')}?" + Date.parse(new Date()))
                    layer.msg(res.msg,{icon:2,time:1500});
                }
            },'json')

            return false;
        });
    });

    $('#captcha').click(function () {
        $(this).attr('src', "{:url('login/captcha')}?" + Date.parse(new Date()))
    })
</script>
{/block}